import {_decorator, Component} from 'cc';
import {AudioManager} from "db://assets/scripts/common/AudioManager";
import {UIManager} from "db://assets/scripts/common/UIManager";
import {AudioPaths} from "db://assets/scripts/common/AudioPaths";

const {ccclass, property} = _decorator;

/**
 * 返回界面控制器
 */
@ccclass('BackController')
export class BackController extends Component {
    /**
     * 回调
     */
    private callback: Function;

    /**
     * 设置回调
     *
     * @param callback 回调
     */
    public setCallback(callback: Function) {
        this.callback = callback;
    }

    /**
     * 确认
     */
    public onConfirm() {
        // 播放音效
        AudioManager.getInstance().playSound(AudioPaths.clickSound);
        // 隐藏弹窗
        UIManager.getInstance().hideDialog("back/backPanel");
        // 回调
        this.callback && this.callback();
    }

    /**
     * 取消
     */
    public onCancel() {
        AudioManager.getInstance().playSound(AudioPaths.clickSound);
        UIManager.getInstance().hideDialog("back/backPanel");
    }
}